package com.yy.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.yy.common.utils.poi.ExcelUtil;
import com.yy.domain.AssetHouseBlock;
import com.yy.service.IAssetHouseBlockService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yy.common.annotation.Log;
import com.yy.common.core.controller.BaseController;
import com.yy.common.core.domain.AjaxResult;
import com.yy.common.enums.BusinessType;



import com.yy.common.core.page.TableDataInfo;

/**
 * 商圈|小区Controller
 * 
 * @author yy
 * @date 2023-10-24
 */
@RestController
@RequestMapping("/system/block")
public class AssetHouseBlockController extends BaseController
{
    @Autowired
    private IAssetHouseBlockService assetHouseBlockService;

    /**
     * 查询商圈|小区列表
     */
    @PreAuthorize("@ss.hasPermi('system:block:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetHouseBlock assetHouseBlock)
    {
        startPage();
        List<AssetHouseBlock> list = assetHouseBlockService.selectAssetHouseBlockList(assetHouseBlock);
        return getDataTable(list);
    }

    /**
     * 导出商圈|小区列表
     */
    @PreAuthorize("@ss.hasPermi('system:block:export')")
    @Log(title = "商圈|小区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetHouseBlock assetHouseBlock)
    {
        List<AssetHouseBlock> list = assetHouseBlockService.selectAssetHouseBlockList(assetHouseBlock);
        ExcelUtil<AssetHouseBlock> util = new ExcelUtil<AssetHouseBlock>(AssetHouseBlock.class);
        util.exportExcel(response, list, "商圈|小区数据");
    }

    /**
     * 获取商圈|小区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:block:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetHouseBlockService.selectAssetHouseBlockById(id));
    }

    /**
     * 新增商圈|小区
     */
    @PreAuthorize("@ss.hasPermi('system:block:add')")
    @Log(title = "商圈|小区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetHouseBlock assetHouseBlock)
    {
        return toAjax(assetHouseBlockService.insertAssetHouseBlock(assetHouseBlock));
    }

    /**
     * 修改商圈|小区
     */
    @PreAuthorize("@ss.hasPermi('system:block:edit')")
    @Log(title = "商圈|小区", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetHouseBlock assetHouseBlock)
    {
        return toAjax(assetHouseBlockService.updateAssetHouseBlock(assetHouseBlock));
    }

    /**
     * 删除商圈|小区
     */
    @PreAuthorize("@ss.hasPermi('system:block:remove')")
    @Log(title = "商圈|小区", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetHouseBlockService.deleteAssetHouseBlockByIds(ids));
    }
}
